<template>
  <!-- 表格 -->
  <el-table class="pageTableClass" :data="taskNoPage" height="calc(100vh - 380px)" :loading="isLoading">
    <el-table-column label="序号" align="center" width="70">
      <template #default="scope">
        {{ (paginationParams.current - 1) * paginationParams.pageSize + scope.$index + 1 }}
      </template>
    </el-table-column>
    <el-table-column prop="code" min-width="150" label="计划编号" align="center"/>
    <el-table-column prop="planName" min-width="150" label="计划名称" align="center"/>
    <el-table-column prop="planDescription" min-width="250" label="计划描述" show-overflow-tooltip align="center"/>
    <el-table-column prop="startDatetime" min-width="180" label="开始时间" align="center"/>
    <el-table-column prop="endDatetime" min-width="180" label="结束时间" align="center"/>
    <el-table-column
        prop="actualTimeCost"
        min-width="150"
        label="实际用时 (min)"
        align="center"
    >
      <template #default="{ row }">
        {{ row.actualTimeCost ? Math.round(row.actualTimeCost / 60) : '' }}
      </template>
    </el-table-column>
    <el-table-column prop="equipmentName" min-width="200" label="设备名称" align="center"/>
    <el-table-column prop="equipmentCode" min-width="200" label="设备编码" align="center"/>
    <el-table-column prop="activeLine" min-width="180" label="触发时间" align="center"/>
    <el-table-column prop="organizationName" min-width="200" label="所属部门" align="center"/>
    <el-table-column prop="planTimeCost" min-width="100" label="计划用时" align="center"/>
    <el-table-column prop="updateName" min-width="180" label="执行人" align="center"/>
    <el-table-column label="操作" align="center" fixed="right" width="100">
      <template #default="scope">

        <el-button style="color:#4160beed" :icon="Tickets" text @click="handleDetails(scope.row)" size="small"
                   plain>详情
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="pagePagination">
    <el-pagination background v-model:current-page="paginationParams.current"
                   v-model:page-size="paginationParams.pageSize" layout="total, sizes, prev, pager, next"
                   :total="pageTotal"
                   @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
  </div>
  <!-- 弹框 -->
  <el-dialog v-model="dialogVisible" title="任务详情" width="60%">
    <el-table class="pageTableClass" :data="contentDialog">
      <el-table-column prop="content" min-width="150" label="点检内容" align="center"/>
      <!--			<el-table-column prop="result" min-width="200" label="结果" align="center" />-->
      <el-table-column prop="describe" min-width="200" label="原因描述" align="center"/>
    </el-table>
    <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">关闭</el-button>
            </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {defineProps, ref, onMounted} from 'vue';
import {ElMessage} from 'element-plus';
import {Tickets} from '@element-plus/icons-vue';

const dialogVisible = ref(false);
const contentDialog = ref([]);
const types = ref([
  {
    label: '设备',
    value: 1
  },
  {
    label: '工装',
    value: 2
  }

]);
const props = defineProps({
  paginationParams: Object,
  onSubmit: Function,
  handleSizeChange: Function,
  handleCurrentChange: Function,
  taskNoPage: Array,
  pageTotal: Number,
  equipmentData: Object,
  fetchPage: Function
});

const handleDetails = (row) => {
  contentDialog.value = JSON.parse(row?.result)?.map(item => ({
    content: item?.content,
    result: item?.result,
    describe: item?.describe
  })) || [];
  dialogVisible.value = true;
};
</script>

<style scoped>
.pageTableClass {
  width: 100%;
}

.pagePagination {
  margin-top: 20px;
  text-align: center;
}
</style>